#ifndef UNION_FIND
#define UNION_FIND

#include <vector>
#include <stdexcept>

class UF
{
public:
    explicit UF(int N);
    void Union(int p,int q);
    int getcount() const;
    bool connected(int p, int q);

private:
    std::vector<int> id;
    std::vector<int> sz; 
    int count;
    //quick union
    int root(int i);
};

#endif